#if (FEATURE_MODE == 0)
/**
 @file ctc_usw_stacking_cli.c

 @date 2010-7-9

 @version v2.0

---file comments----
*/

#include "ctc_cli.h"
#include "ctc_cli_common.h"
#include "ctc_error.h"
#include "ctc_api.h"
#include "ctcs_api.h"
#include "ctc_debug.h"
#include "ctc_usw_stacking_cli.h"
extern int32 _sys_usw_stacking_set_trunk_mode(uint8 lchip, uint8 mode);
extern int32 sys_usw_stacking_show_trunk_info(uint8 lchip, uint8 trunk_id);
extern int32 sys_usw_stacking_show_status(uint8 lchip);
extern int32 sys_usw_stacking_show_trunk_brief(uint8 lchip);
extern int32 sys_usw_stacking_trunk_set_rr_en(uint8 lchip, uint8 trunk_id, uint8 rr_en);
extern int32 sys_usw_stacking_mcast_mode(uint8 lchip, uint8 mcast_mode);
extern int32 sys_usw_stacking_src_port_mode(uint8 lchip, uint8 src_port_mode);
extern int32 _sys_usw_stacking_all_mcast_bind_en(uint8 lchip, uint8 enable);
extern int32 sys_usw_stacking_update_load_mode(uint8 lchip, uint8 trunk_id, ctc_stacking_load_mode_t load_mode);
extern int32 _sys_usw_stacking_set_learning_mode(uint8 lchip, ctc_stacking_learning_mode_t learning_mode);

CTC_CLI(ctc_cli_usw_stacking_show_trunk_info,
        ctc_cli_usw_stacking_show_trunk_info_cmd,
        "show stacking trunk trunk-id TRUNID info",
        "Show",
        "Stacking",
        "Trunk",
        "Trunk id",
        "Value <1-63>",
        "Information"
        )
{
    uint8 trunk_id = 0;
    int32 ret = CLI_SUCCESS;
    CTC_CLI_GET_UINT8_RANGE("Trunkid", trunk_id, argv[0], 0, CTC_MAX_UINT8_VALUE);

    ret = sys_usw_stacking_show_trunk_info(g_api_lchip, trunk_id);
    if (ret < 0)
    {
        ctc_cli_out("%% ret=%d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_stacking_show_trunk_brief,
        ctc_cli_usw_stacking_show_trunk_brief_cmd,
        "show stacking trunk brief ",
        "Show",
        "Stacking",
        "Trunk",
        "Brief"
        )
{
    int32 ret = CLI_SUCCESS;

    ret = sys_usw_stacking_show_trunk_brief(g_api_lchip);

    if (ret < 0)
    {
        ctc_cli_out("%% ret=%d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_stacking_show_status,
        ctc_cli_usw_stacking_show_status_cmd,
        "show stacking status)",
        "Show",
        "Stacking",
        "Status")
{
    int32 ret = CLI_SUCCESS;

    ret = sys_usw_stacking_show_status(g_api_lchip);
    if (ret < 0)
    {
        ctc_cli_out("%% ret=%d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}
CTC_CLI(ctc_cli_usw_stacking_mcast_mode,
        ctc_cli_usw_stacking_mcast_mode_cmd,
        "stacking mcast-mode MODE",
        "Stacking",
        "Mcast mode",
        "0: add trunk to mcast group auto; 1: add trunk to mcast group by user"
        )
{
    int32 ret = CLI_SUCCESS;
    uint8 mode = 0;

    CTC_CLI_GET_UINT8("mode", mode, argv[0]);

    ret = sys_usw_stacking_mcast_mode(g_api_lchip, mode);
    if (ret < 0)
    {
        ctc_cli_out("%% ret=%d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_stacking_mcast_bind_en,
        ctc_cli_usw_stacking_mcast_bind_en_cmd,
        "stacking mcast bind (enable|disable)",
        "Stacking",
        "Mcast",
        "Bind default profile",
        "Enable",
        "Disable"
        )
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    uint8 enable = 0;

    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
        enable = 1;
    }

    ret = _sys_usw_stacking_all_mcast_bind_en(g_api_lchip, enable);
    if (ret < 0)
    {
        ctc_cli_out("%% ret=%d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_stacking_update_load_mode,
        ctc_cli_usw_stacking_update_load_mode_cmd,
        "stacking update (trunk TRUNID) (load-mode MODE)",
        "Stacking",
        "Update",
        "Trunk",
        "Trunk id",
        "Load mode",
        "MODE"
        )
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    uint8 trunk_id = 0;
    uint8 load_mode = 0;

    index = CTC_CLI_GET_ARGC_INDEX("trunk");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("trunk", trunk_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("load-mode");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("load-mode", load_mode, argv[index + 1]);
    }

    ret = sys_usw_stacking_update_load_mode(g_api_lchip, trunk_id, load_mode);
    if (ret < 0)
    {
        ctc_cli_out("%% ret=%d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}


CTC_CLI(ctc_cli_usw_stacking_update_trunk_mode,
        ctc_cli_usw_stacking_update_trunk_mode_cmd,
        "stacking update trunk-mode MODE",
        "Stacking",
        "update",
        "Trunk mode",
        "MODE"
        )
{
    int32 ret = CLI_SUCCESS;
    uint8 trunk_mode = 0;


    CTC_CLI_GET_UINT8("mode", trunk_mode, argv[0]);

    ret = _sys_usw_stacking_set_trunk_mode(g_api_lchip, trunk_mode);
    if (ret < 0)
    {
        ctc_cli_out("%% ret=%d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_stacking_set_trunk_rr_en,
        ctc_cli_usw_stacking_set_trunk_rr_en_cmd,
        "stacking update trunk TRUNID rr-en (enable|disable)",
        "Stacking",
        "Set",
        "Trunk",
        "Trunk ID",
        "RR mode",
        "Enable",
        "Disable"
        )
{
    int32 ret = CLI_SUCCESS;
    uint8 index = 0;
    uint8 trunk_id = 0;
    uint8 rr_en = 0;

    CTC_CLI_GET_UINT8("mode", trunk_id, argv[0]);

    index = CTC_CLI_GET_ARGC_INDEX("enable");
    if (0xFF != index)
    {
        rr_en = 1;
    }

    ret = sys_usw_stacking_trunk_set_rr_en(g_api_lchip, trunk_id, rr_en);
    if (ret < 0)
    {
        ctc_cli_out("%% ret=%d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_stacking_src_port_mode,
        ctc_cli_usw_stacking_src_port_mode_cmd,
        "stacking src-port-mode MODE",
        "Stacking",
        "Src port mode",
        "0:use src gport+remote chip to select ucast path; 1: use forward select group id+remote chip to select ucast path;  2: use remote chip 3: use src gport lb hash to select ucast path(default: 0)"
        )
{
    int32 ret = CLI_SUCCESS;
    uint8 mode = 0;

    CTC_CLI_GET_UINT8("mode", mode, argv[0]);

    ret = sys_usw_stacking_src_port_mode(g_api_lchip, mode);
    if (ret < 0)
    {
        ctc_cli_out("%% ret=%d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_usw_stacking_learning_mode,
        ctc_cli_usw_stacking_learning_mode_cmd,
        "stacking learning-mode MODE",
        "Stacking",
        "Learning mode",
        "0:learning by stacking header; 1: learning by re-parser packet, only for basic L2 forwarding; 2:don't learning for no-first chip"
        )
{
    int32 ret = CLI_SUCCESS;
    uint8 mode = 0;

    CTC_CLI_GET_UINT8("mode", mode, argv[0]);

    ret = _sys_usw_stacking_set_learning_mode(g_api_lchip, mode);
    if (ret < 0)
    {
        ctc_cli_out("%% ret=%d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

int32
ctc_usw_stacking_cli_init(void)
{
	install_element(CTC_SDK_MODE,  &ctc_cli_usw_stacking_show_status_cmd);
    install_element(CTC_SDK_MODE,  &ctc_cli_usw_stacking_show_trunk_info_cmd);
    install_element(CTC_SDK_MODE,  &ctc_cli_usw_stacking_show_trunk_brief_cmd);

    install_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_mcast_mode_cmd);
    install_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_mcast_bind_en_cmd);
    install_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_update_load_mode_cmd);
    install_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_update_trunk_mode_cmd);
    install_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_src_port_mode_cmd);
    install_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_learning_mode_cmd);
    install_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_set_trunk_rr_en_cmd);

    return CLI_SUCCESS;

}

int32
ctc_usw_stacking_cli_deinit(void)
{
	uninstall_element(CTC_SDK_MODE,  &ctc_cli_usw_stacking_show_status_cmd);
    uninstall_element(CTC_SDK_MODE,  &ctc_cli_usw_stacking_show_trunk_info_cmd);
    uninstall_element(CTC_SDK_MODE,  &ctc_cli_usw_stacking_show_trunk_brief_cmd);

    uninstall_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_mcast_mode_cmd);
    uninstall_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_mcast_bind_en_cmd);
    uninstall_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_update_load_mode_cmd);
    uninstall_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_update_trunk_mode_cmd);
    uninstall_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_src_port_mode_cmd);
    uninstall_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_learning_mode_cmd);
    uninstall_element(CTC_INTERNAL_MODE,  &ctc_cli_usw_stacking_set_trunk_rr_en_cmd);

    return CLI_SUCCESS;

}

#endif

